package com.example.hp.yuejian5.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hp.yuejian5.R;

import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.ActivityBean;
import com.example.hp.yuejian5.model.Activity_DetailModel;
import com.squareup.picasso.Picasso;
import android.support.v7.app.AppCompatActivity;

import static com.example.hp.yuejian5.other.url.PICTURE;

public class Activity_DetailActivity extends AppCompatActivity {
    private String i_id, u_id;
    private Context context;
    private FragmentTransaction fragmentTransaction;
    private FragmentManager fragmentManager;
    private RetrofitListener<ActivityBean> listener;

    private ImageView activity_detail_pic;
    private Toolbar toolbar;
    private TextView baoming;
    private TextView toolbartitle;
    private int flagattention;
    private SharedPreferences sp;
    private TextView activity_detail_address,activity_detail_title,activity_detail_tel,activity_detail_aprice,activity_detail_sprice,activity_detail_notice,activity_detail_time,activity_detail_toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_activity_detail);
        setSupportActionBar(toolbar);
        Intent intent = getIntent();
        i_id = (String) intent.getStringExtra("a_id");
        sp = getSharedPreferences("user_id", Context.MODE_PRIVATE);
        u_id = sp.getString("userid", null);
        initView();
        viewListener();
        listener = new RetrofitListener<ActivityBean>() {
            @Override
            public void onSuccess(ActivityBean activityBean, int flag) {
                activity_detail_address.setText(activityBean.getActivity_address());
                activity_detail_title.setText(activityBean.getActivity_title());
                activity_detail_tel.setText(activityBean.getActivity_tel());
                activity_detail_aprice.setText(activityBean.getActivity_aprice());
                activity_detail_sprice.setText(activityBean.getActivity_sprice());
                activity_detail_notice.setText(activityBean.getActivity_notice());
                activity_detail_time.setText(activityBean.getActivity_time());
                Picasso.with(context).load(PICTURE + activityBean.getActivity_pic()).into(activity_detail_pic);
            }

            @Override
            public void onFail() {

            }
        };


        activityDetail();

    }

    private void initView() {
        activity_detail_title=findViewById(R.id.activity_detail_title);
        activity_detail_pic = findViewById(R.id.activity_detail_pic);
        activity_detail_address = findViewById(R.id.activity_detail_address);
        activity_detail_notice = findViewById(R.id.activity_detail_notice);
        activity_detail_tel = findViewById(R.id.activity_detail_tel);
        activity_detail_aprice = findViewById(R.id.activity_detail_aprice);
        activity_detail_sprice = findViewById(R.id.activity_detail_sprice);
        activity_detail_time = findViewById(R.id.activity_detail_time);
        baoming=findViewById(R.id.baoming);
        toolbar = findViewById(R.id.activity_detail_toolbar);
        toolbartitle = findViewById(R.id.activity_detail_toolbar_text);
    }

    private void viewListener() {

        baoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent (Activity_DetailActivity.this,ActivityorderActivity.class);
                intent.putExtra("a_id", i_id);
                startActivity(intent);
            }
        });
    }
    private void activityDetail() {
        Activity_DetailModel club_detailModel = new Activity_DetailModel();
        club_detailModel.activityDetail(i_id, listener);
    }


}
